{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 126
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "Xfrg3qJ857zS",
    "outputId": "b2ef077d-09f1-481d-b794-924cdfcac1dc"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pymysql\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/ed/39/15045ae46f2a123019aa968dfcba0396c161c20f855f11dea6796bcaae95/PyMySQL-0.9.3-py2.py3-none-any.whl (47kB)\n",
      "\u001b[K    100% |████████████████████████████████| 51kB 3.5MB/s \n",
      "\u001b[?25hInstalling collected packages: pymysql\n",
      "Successfully installed pymysql-0.9.3\n"
     ]
    }
   ],
   "source": [
    "!pip install pymysql"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 159
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "WXKEkEzink_m",
    "outputId": "0c7975bc-1d4a-4b54-81c1-2516ad5ce4ce"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting git+https://github.com/coreylynch/pyFM\n",
      "  Cloning https://github.com/coreylynch/pyFM to /tmp/pip-req-build-hmq3macr\n",
      "Building wheels for collected packages: pyfm\n",
      "  Running setup.py bdist_wheel for pyfm ... \u001b[?25l-\b \b\\\b \b|\b \b/\b \b-\b \b\\\b \bdone\n",
      "\u001b[?25h  Stored in directory: /tmp/pip-ephem-wheel-cache-5dnpy1h3/wheels/3b/d9/ef/1b148c527d39344632833679e79b3db1798a40b0f64f917b13\n",
      "Successfully built pyfm\n",
      "Installing collected packages: pyfm\n",
      "Successfully installed pyfm-0.0.0\n"
     ]
    }
   ],
   "source": [
    "!pip install git+https://github.com/coreylynch/pyFM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Qr4yc61W57Ic"
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import pymysql\n",
    "import pymysql.cursors\n",
    "from functools import reduce\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import uuid\n",
    "import datetime\n",
    "from pyfm import pylibfm\n",
    "from sklearn.feature_extraction import DictVectorizer\n",
    "from sklearn.metrics.pairwise import pairwise_distances\n",
    "np.set_printoptions(precision=3)\n",
    "np.set_printoptions(suppress=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "4Rdfk--W5-BA"
   },
   "outputs": [],
   "source": [
    "def get_connection():\n",
    "    return pymysql.connect(host='47.244.123.248',\n",
    "                               user='root',\n",
    "                               password='demo12DB',\n",
    "                               db='recsys',\n",
    "                               port=3306,\n",
    "                               charset ='utf8',\n",
    "                               use_unicode=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "85xHY1TA6MnC"
   },
   "outputs": [],
   "source": [
    "df = pd.read_sql_query(\"select * from movie\", get_connection())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Wnd8Gwsk6tLv"
   },
   "outputs": [],
   "source": [
    "#df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "e4lQur0O67k0"
   },
   "outputs": [],
   "source": [
    "#df_exp = df.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "CcJVn59xWoDT"
   },
   "outputs": [],
   "source": [
    "#df_exp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "0TEiUd1MeqUp"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "nLE09L4bgrwg"
   },
   "outputs": [],
   "source": [
    "def get_dim_dict(df, dim_name):\n",
    "  type_list = list(map(lambda x:x.split('|') ,df[dim_name]))\n",
    "  type_list = [x for l in type_list for x in l]\n",
    "  def reduce_func(x, y):\n",
    "    for i in x:\n",
    "      if i[0] == y[0][0]:\n",
    "        x.remove(i)\n",
    "        x.append(((i[0],i[1] + 1)))\n",
    "        return x\n",
    "    x.append(y[0])\n",
    "    return x\n",
    "  l = filter(lambda x:x != None, map(lambda x:[(x, 1)], type_list))\n",
    "  type_zip = reduce(reduce_func, list(l))\n",
    "  #type_list = sorted(list(set(type_list)))\n",
    "  #type_zip = zip(list(range(len(type_list))), type_list)\n",
    "  #print(len(type_zip))\n",
    "  #print(type_zip)\n",
    "  type_dict = {}\n",
    "  for i in type_zip:\n",
    "    type_dict[i[0]] = i[1]\n",
    "  return type_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "NgCL3BIGjYua"
   },
   "outputs": [],
   "source": [
    "type_dict = get_dim_dict(df, 'type')\n",
    "actors_dict = get_dim_dict(df, 'actors')\n",
    "director_dict = get_dim_dict(df, 'director')\n",
    "trait_dict = get_dim_dict(df, 'trait')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "aKGvytP_lSOe"
   },
   "outputs": [],
   "source": [
    "#print(type_dict)\n",
    "#print(actors_dict)\n",
    "#print(director_dict)\n",
    "#print(trait_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Zauqzs6v8r7h"
   },
   "outputs": [],
   "source": [
    "#director_dict['吉姆·弗尔']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "vG6UtDPM8zCw"
   },
   "outputs": [],
   "source": [
    "#actors_dict['马克·莱昂纳蒂']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "DlYjtQt3mcUM"
   },
   "outputs": [],
   "source": [
    "df_ = df.drop(['ADD_TIME', 'enable', 'rat', 'id', 'name'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "xuCi-7VAuBkW"
   },
   "outputs": [],
   "source": [
    "#df_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Y2sXwXAhz1FA"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "jicjc-23oFRO"
   },
   "outputs": [],
   "source": [
    "movie_dict_list = []\n",
    "for i in df_.index:\n",
    "  movie_dict = {}\n",
    "  #type\n",
    "  for s_type in df_.iloc[i]['type'].split('|'):\n",
    "    movie_dict[s_type] = 1\n",
    "  #actors\n",
    "  for s_actor in df_.iloc[i]['actors'].split('|'):\n",
    "    if actors_dict[s_actor] < 2:\n",
    "      movie_dict['other_actor'] = 1\n",
    "    else:\n",
    "      movie_dict[s_actor] = 1\n",
    "  #regios\n",
    "  movie_dict[df_.iloc[i]['region']] = 1\n",
    "  #director\n",
    "  for s_director in df_.iloc[i]['director'].split('|'):\n",
    "    if director_dict[s_director] < 2:\n",
    "      movie_dict['other_director'] = 1\n",
    "    else:\n",
    "      movie_dict[s_director] = 1\n",
    "  #trait\n",
    "  for s_trait in df_.iloc[i]['trait'].split('|'):\n",
    "    movie_dict[s_trait] = 1\n",
    "  movie_dict_list.append(movie_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "DwakpcbVvGmu"
   },
   "outputs": [],
   "source": [
    "v = DictVectorizer()\n",
    "X = v.fit_transform(movie_dict_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 170
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "CN9Br9TS-o2A",
    "outputId": "b867003d-2432-4fa4-c43c-c0c5acd3ce3c"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'other_actor': 1,\n",
       " 'other_director': 1,\n",
       " '冈本信彦': 1,\n",
       " '冒险': 1,\n",
       " '剧情': 1,\n",
       " '日本': 1,\n",
       " '爱情': 1,\n",
       " '科幻': 1,\n",
       " '青春': 1}"
      ]
     },
     "execution_count": 97,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie_dict_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 170
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "rhb2GHdMwJ4l",
    "outputId": "6c0a50b5-6c10-4cf6-8bcd-8531c16d459b"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "96\n",
      "97\n",
      "749\n",
      "756\n",
      "923\n",
      "2575\n",
      "3570\n",
      "3928\n",
      "5548\n"
     ]
    }
   ],
   "source": [
    "index = 0\n",
    "l = X[0].todense().tolist()[0]\n",
    "for i in l:\n",
    "  #print('i:'+str(i))\n",
    "  if str(i) == '1.0':\n",
    "    print(index)\n",
    "  index = index + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "5BU4mJeCAbYz"
   },
   "outputs": [],
   "source": [
    "dict_sigle = {'other_actor': 1,\n",
    " 'other_director': 1,\n",
    " '冈本信彦': 1,\n",
    " '冒险': 1,\n",
    " '剧情': 1,\n",
    " '日本': 1,\n",
    " '爱情': 1,\n",
    " '科幻': 1,\n",
    " '青春2': 1}\n",
    "vec = v.transform(dict_sigle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 153
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "dSCXe-CLApFW",
    "outputId": "1a678bba-5052-408f-b92c-c38c7606a053"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "96\n",
      "97\n",
      "749\n",
      "756\n",
      "923\n",
      "2575\n",
      "3570\n",
      "3928\n"
     ]
    }
   ],
   "source": [
    "index = 0\n",
    "l = vec.todense().tolist()[0]\n",
    "for i in l:\n",
    "  #print('i:'+str(i))\n",
    "  if str(i) == '1.0':\n",
    "    print(index)\n",
    "  index = index + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "LcE1Ir5HSk-_"
   },
   "outputs": [],
   "source": [
    "#pd.DataFrame(data=X.toarray(), columns=v.feature_names_).T.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "5L8l65lg7AoE"
   },
   "outputs": [],
   "source": [
    "item_similarity = pairwise_distances(X, metric='cosine')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "YEEu1ZhQVL6P"
   },
   "outputs": [],
   "source": [
    "#item_similarity.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "UUcGZ5FMVQSm",
    "outputId": "0b959691-b929-4dcd-f269-95fdc0e956ca"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3634 0.2587506833388987\n"
     ]
    }
   ],
   "source": [
    "compare_index = 3\n",
    "index = 0\n",
    "_max_index = 0\n",
    "_max = 1\n",
    "for i in item_similarity[compare_index]:\n",
    "  if i < _max and i != 0:\n",
    "    _max = i\n",
    "    _max_index = index\n",
    "  index = index + 1\n",
    "print(_max_index, _max)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "S06VsY4cFgA6"
   },
   "outputs": [],
   "source": [
    "index_of_sim = _max_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 336
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "LMP8ylRWVMqn",
    "outputId": "b680c99f-380f-4f48-c7fa-0f2df5b147b2"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                  0    1\n",
      "other_actor     1.0  1.0\n",
      "other_director  1.0  1.0\n",
      "丹尼·博伊尔          0.0  1.0\n",
      "佩丽冉卡·曹帕拉        1.0  0.0\n",
      "剧情              1.0  1.0\n",
      "励志              1.0  1.0\n",
      "印度              1.0  1.0\n",
      "喜剧              1.0  1.0\n",
      "感人              1.0  1.0\n",
      "戴夫·帕特尔          0.0  1.0\n",
      "搞笑              1.0  0.0\n",
      "文艺              1.0  0.0\n",
      "沙鲁巴·舒克拉         1.0  1.0\n",
      "爱情              1.0  1.0\n",
      "经典              1.0  1.0\n",
      "青春              0.0  1.0\n",
      "音乐              1.0  0.0\n"
     ]
    }
   ],
   "source": [
    "df.iloc[index_of_sim]\n",
    "movie_dict_list[index_of_sim]\n",
    "df_106 = pd.DataFrame(data=X.todense()[index_of_sim], columns=v.feature_names_)\n",
    "df_0 = pd.DataFrame(data=X.todense()[compare_index], columns=v.feature_names_)\n",
    "df_diff = pd.concat([df_0, df_106], axis=0, ignore_index=True)\n",
    "#df_diff.reindex(['0','1'])\n",
    "df_diff = df_diff.T\n",
    "print(df_diff[(df_diff[0] != 0) | (df_diff[1] != 0)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "HZVO4bHXyHEU"
   },
   "outputs": [],
   "source": [
    "#df.iloc[index_of_sim]\n",
    "#movie_dict_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "4jWBmBMczT1O"
   },
   "outputs": [],
   "source": [
    "#df.iloc[compare_index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "7TzGxhlozd6O"
   },
   "outputs": [],
   "source": [
    "#item_similarity.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "75SRFh7lZEqh"
   },
   "outputs": [],
   "source": [
    "# li_dict = {1:0.1, 2:0.2, 5:0.4, 8:0.3}\n",
    "# min(li_dict.values())\n",
    "# dict(filter(lambda x:x[1] != 0.4 ,li_dict.items()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "wpWxp2eNbn3C"
   },
   "outputs": [],
   "source": [
    "df_sim = pd.DataFrame(data=item_similarity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "ibs6QhZ-c_32"
   },
   "outputs": [],
   "source": [
    "#df_sim.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "V54pDt7Io2gQ"
   },
   "outputs": [],
   "source": [
    "def insert_one_ibmovie(id_,\n",
    "                      movieid,\n",
    "                      recmovieid,\n",
    "                      recmovierat,\n",
    "                      simrat,\n",
    "                      time,\n",
    "                      enable, connection):\n",
    "  sql = 'insert into ibmovie (id, movieid, recmovieid, recmovierat, simrat, time, enable) values (\\'%s\\',\\'%s\\',\\'%s\\',\\'%s\\',\\'%s\\',\\'%s\\',\\'%s\\')' % (id_, movieid, recmovieid, recmovierat, simrat, time, enable)\n",
    "  #print(sql)\n",
    "  try:\n",
    "    with connection.cursor() as cursor:\n",
    "        cout=cursor.execute(sql)\n",
    "  except Exception as e:\n",
    "    print('exception:'+str(e))\n",
    "    try:\n",
    "      connection.close()\n",
    "    except:\n",
    "      pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "6rZZt9yLuclQ"
   },
   "source": [
    "## Test code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "ztxAOQqIubhc"
   },
   "outputs": [],
   "source": [
    "# _conn = get_connection()\n",
    "# insert_one_ibmovie(uuid.uuid4(), '1', '2', '6', '0.1', datetime.datetime.now(), '1', _conn)\n",
    "# _conn.commit()\n",
    "# _conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "wqxqYx-uv0Xt"
   },
   "outputs": [],
   "source": [
    "# df_sim.nsmallest(10, 0)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "DLOuZrnMqkvL"
   },
   "outputs": [],
   "source": [
    "def get_recmovie_cnt_by_movieid(movieid, connection):\n",
    "  sql = 'select count(*) from ibmovie group by movieid having movieid=\\'%s\\'' % movieid\n",
    "  try:  \n",
    "    with connection.cursor() as cursor:\n",
    "      cout=cursor.execute(sql)\n",
    "      if cout == 0:\n",
    "        return 0\n",
    "      return cursor.fetchone()[0]  \n",
    "  except Exception as e:\n",
    "    print('exception@get_recmovie_by_movieid:'+str(e))\n",
    "    try:\n",
    "      connection.cursor().close()\n",
    "      connection.close()\n",
    "      print('closed')\n",
    "    except Exception as e1:\n",
    "      print('exception1@get_recmovie_by_movieid:' + str(e1))\n",
    "    connection = get_connection()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 35
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "yrvahS3UrUUA",
    "outputId": "8b243cfa-df02-464f-9766-243e8a652414"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "cnt = get_recmovie_cnt_by_movieid('10746430_', get_connection())\n",
    "print(cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 212
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "XfCBrL-8N0t3",
    "outputId": "13b1c74e-f70e-46d5-b809-261a645d32cd"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "id                                       1794438\n",
       "name                                          铁拳\n",
       "ADD_TIME                     2018-02-07 20:59:54\n",
       "type                     武侠|奇幻|剧情|犯罪|传记|喜剧|科幻|动作\n",
       "actors      杰克·吉伦哈尔|福里斯特·惠特克|瑞秋·麦克亚当斯|乌娜·劳伦斯|50分\n",
       "region                                        美国\n",
       "director                                 安东尼·福奎阿\n",
       "trait                                   感人|励志|搞笑\n",
       "rat                                          7.2\n",
       "enable                                         1\n",
       "Name: 2850, dtype: object"
      ]
     },
     "execution_count": 37,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[2850]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "I-h9C8SvN0AG"
   },
   "outputs": [],
   "source": [
    "start_index = 2849\n",
    "start_index = 2961\n",
    "start_index = 2991"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "XGB59Ne87LGy"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "TZYb1opSbyAB"
   },
   "outputs": [],
   "source": [
    "def process_offline_compute_by_cosdis(rec_per_num):\n",
    "  rec_per_num = rec_per_num + 1\n",
    "  connection = get_connection()\n",
    "  for i in range(start_index, item_similarity.shape[0]):\n",
    "    df_sim_p = df_sim.nsmallest(rec_per_num, i)\n",
    "    df_sim_p = df_sim_p[i]\n",
    "    movie_id = df.iloc[i]['id']\n",
    "    recmovie_cnt = get_recmovie_cnt_by_movieid(movie_id, connection)\n",
    "    if recmovie_cnt == 200:\n",
    "      print('org...')\n",
    "      continue\n",
    "    print('new...')\n",
    "    time_now = datetime.datetime.now()\n",
    "    for rec_movie_item in df_sim_p.to_dict().items():\n",
    "      if rec_movie_item[0] != i:\n",
    "        rec_movie_index = rec_movie_item[0]\n",
    "        rec_movie_sim = rec_movie_item[1]\n",
    "        rec_movie_id = df.iloc[rec_movie_index]['id']\n",
    "        rec_movie_rat = df.iloc[rec_movie_index]['rat']\n",
    "        insert_one_ibmovie(id_=uuid.uuid4(), movieid=movie_id, recmovieid=rec_movie_id, recmovierat=rec_movie_rat, simrat=rec_movie_sim, time=time_now, enable='1', connection=connection)\n",
    "    connection.commit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 3375
    },
    "colab_type": "code",
    "collapsed": false,
    "id": "XyDv1CbL0Kw8",
    "outputId": "d5c13cb1-b2e6-4597-9ca3-503b2416d44e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "org...\n",
      "org...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n",
      "new...\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "ignored",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-103-d17e4a53d8bd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprocess_offline_compute_by_cosdis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrec_per_num\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m200\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m<ipython-input-102-60d661222a24>\u001b[0m in \u001b[0;36mprocess_offline_compute_by_cosdis\u001b[0;34m(rec_per_num)\u001b[0m\n\u001b[1;32m     18\u001b[0m         \u001b[0mrec_movie_id\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrec_movie_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'id'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     19\u001b[0m         \u001b[0mrec_movie_rat\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrec_movie_index\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'rat'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 20\u001b[0;31m         \u001b[0minsert_one_ibmovie\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mid_\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0muuid\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muuid4\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmovieid\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmovie_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecmovieid\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrec_movie_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecmovierat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrec_movie_rat\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msimrat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrec_movie_sim\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtime_now\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0menable\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'1'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconnection\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mconnection\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     21\u001b[0m     \u001b[0mconnection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-32-252b4c3f502e>\u001b[0m in \u001b[0;36minsert_one_ibmovie\u001b[0;34m(id_, movieid, recmovieid, recmovierat, simrat, time, enable, connection)\u001b[0m\n\u001b[1;32m     10\u001b[0m   \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     11\u001b[0m     \u001b[0;32mwith\u001b[0m \u001b[0mconnection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcursor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mcursor\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m         \u001b[0mcout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcursor\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msql\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     13\u001b[0m   \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     14\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'exception:'\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/cursors.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, query, args)\u001b[0m\n\u001b[1;32m    168\u001b[0m         \u001b[0mquery\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmogrify\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    169\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 170\u001b[0;31m         \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_query\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    171\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_executed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mquery\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    172\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/cursors.py\u001b[0m in \u001b[0;36m_query\u001b[0;34m(self, q)\u001b[0m\n\u001b[1;32m    326\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_last_executed\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mq\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    327\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_clear_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 328\u001b[0;31m         \u001b[0mconn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mq\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    329\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_do_get_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    330\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrowcount\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/connections.py\u001b[0m in \u001b[0;36mquery\u001b[0;34m(self, sql, unbuffered)\u001b[0m\n\u001b[1;32m    515\u001b[0m                 \u001b[0msql\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msql\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencoding\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'surrogateescape'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    516\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_execute_command\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mCOMMAND\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCOM_QUERY\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msql\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 517\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_affected_rows\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_read_query_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0munbuffered\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0munbuffered\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    518\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_affected_rows\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    519\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/connections.py\u001b[0m in \u001b[0;36m_read_query_result\u001b[0;34m(self, unbuffered)\u001b[0m\n\u001b[1;32m    730\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    731\u001b[0m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMySQLResult\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 732\u001b[0;31m             \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    733\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_result\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    734\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mserver_status\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/connections.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m   1073\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1074\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1075\u001b[0;31m             \u001b[0mfirst_packet\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconnection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_read_packet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1076\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1077\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mfirst_packet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_ok_packet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/connections.py\u001b[0m in \u001b[0;36m_read_packet\u001b[0;34m(self, packet_type)\u001b[0m\n\u001b[1;32m    655\u001b[0m         \u001b[0mbuff\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34mb''\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    656\u001b[0m         \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 657\u001b[0;31m             \u001b[0mpacket_header\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_read_bytes\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    658\u001b[0m             \u001b[0;31m#if DEBUG: dump_packet(packet_header)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    659\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/pymysql/connections.py\u001b[0m in \u001b[0;36m_read_bytes\u001b[0;34m(self, num_bytes)\u001b[0m\n\u001b[1;32m    689\u001b[0m         \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    690\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 691\u001b[0;31m                 \u001b[0mdata\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_rfile\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum_bytes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    692\u001b[0m                 \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    693\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mIOError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mOSError\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/lib/python3.6/socket.py\u001b[0m in \u001b[0;36mreadinto\u001b[0;34m(self, b)\u001b[0m\n\u001b[1;32m    584\u001b[0m         \u001b[0;32mwhile\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    585\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 586\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sock\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecv_into\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    587\u001b[0m             \u001b[0;32mexcept\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    588\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_timeout_occurred\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "process_offline_compute_by_cosdis(rec_per_num=200)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "Fdnm4mx8d-nK"
   },
   "outputs": [],
   "source": [
    "# df_sim_3_dict = df_sim_3[4].to_dict()\n",
    "# for i in df_sim_3_dict.items():\n",
    "#   print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "4hfc0klZurPx"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "UxcwbK11YPVU"
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "collapsed": true,
    "id": "yCjdKv03YpUm"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "anaconda-cloud": {},
  "colab": {
   "collapsed_sections": [],
   "name": "recbycontent_v1.ipynb",
   "provenance": [],
   "version": "0.3.2"
  },
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
